package com.jiyinit.web.core.business.dao;

import com.jiyinit.core.framework.base.paging.PagingResult;
import com.jiyinit.core.framework.dao.mybatis.base.MybatisDaoContext;
import com.jiyinit.core.framework.dao.mybatis.paginator.domain.PageBounds;
import com.jiyinit.web.core.business.dto.NoticePageRequest;
import com.jiyinit.web.core.business.dto.NoticeRequest;
import com.jiyinit.web.core.business.entity.TabCoreNoticeEntity;
import com.jiyinit.web.core.business.entity.TabSendMessageEntity;
import com.jiyinit.web.core.business.entity.TabUserNoticeEntity;
import com.jiyinit.web.core.business.vo.NoticeVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

/**
 * <p></p>
 * <p/>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author changly
 * @version 1.0
 * @date 2017/12/29 17:51
 * @since 1.0
 */
@Repository("core.tabCoreNoticeDao")
public class TabCoreNoticeDao {

    /**
     * 日志对象
     */
    private static Logger logger = LoggerFactory.getLogger(TabCoreNoticeDao.class);

    private String SQLID = "core.tabCoreNotice.";

    @Autowired
    @Qualifier("core.MybatisDaoContext")
    private MybatisDaoContext mybatisDaoContext;

    public List<TabCoreNoticeEntity> findTaskByIds(List<TabSendMessageEntity> list){
        return mybatisDaoContext.findAll(SQLID+"findTaskByIds",TabCoreNoticeEntity.class,list);
    }

    public int add(TabCoreNoticeEntity entity){
        return mybatisDaoContext.save(SQLID+"insertSelective",entity);
    }

    public TabCoreNoticeEntity findById(Integer id){
        return mybatisDaoContext.findOne(SQLID+"selectByPrimaryKey",TabCoreNoticeEntity.class,id);
    }

    public NoticeVo selectById(Integer id){
        return mybatisDaoContext.findOne(SQLID+"selectAllByPrimaryKey",NoticeVo.class,id);
    }

    public int update(TabCoreNoticeEntity entity){
        return mybatisDaoContext.update(SQLID+"updateByPrimaryKeySelective",entity);
    }

    public NoticeVo findDetailById(Integer id){
        return mybatisDaoContext.findOne(SQLID+"findDetailById",NoticeVo.class,id);
    }

    public int delete(Integer noticeId,Integer userId){
        HashMap<String,Object> params = new HashMap<>();
        params.put("noticeId",noticeId);
        params.put("userId",userId);
        return mybatisDaoContext.update(SQLID+"delete",params);
    }

    public PagingResult<NoticeVo> findPublishByPage(NoticeRequest request){
        HashMap<String,Object> params = new HashMap<>();
        params.put("title",request.getTitle());
        params.put("startTime",request.getStartTime());
        params.put("endTime",request.getEndTime());
        params.put("userId",request.getUserId());

        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(request.getLimit());
        pageBounds.setPage(request.getPage());
        return mybatisDaoContext.findForPage(SQLID+"findPublishByPage",NoticeVo.class,params,pageBounds);
    }
    public PagingResult<NoticeVo> findReceviceByPage(NoticeRequest request){
        HashMap<String,Object> params = new HashMap<>();
        params.put("title",request.getTitle());
        params.put("startTime",request.getStartTime());
        params.put("endTime",request.getEndTime());
        params.put("userId",request.getUserId());

        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(request.getLimit());
        pageBounds.setPage(request.getPage());
        return mybatisDaoContext.findForPage(SQLID+"findReceviceByPage",NoticeVo.class,params,pageBounds);
    }
    public PagingResult<NoticeVo> findByPageForMobile(NoticeRequest request){
        HashMap<String,Object> params = new HashMap<>();
        params.put("title",request.getTitle());
        params.put("startTime",request.getStartTime());
        params.put("endTime",request.getEndTime());
        params.put("userId",request.getUserId());

        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(request.getLimit());
        pageBounds.setPage(request.getPage());
        return mybatisDaoContext.findForPage(SQLID+"findByPageForMobile",NoticeVo.class,params,pageBounds);
    }

    public PagingResult<NoticeVo> findByPage(NoticePageRequest request){
        HashMap<String,Object> params = new HashMap<>();
        params.put("title",request.getTitle());
        params.put("startTime",request.getStartTime());
        params.put("endTime",request.getEndTime());
        params.put("userId",request.getUserId());

        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(request.getLimit());
        pageBounds.setPage(request.getPage());
        return mybatisDaoContext.findForPage(SQLID+"findByPage",NoticeVo.class,params,pageBounds);
    }


    public int updatePreviewNum(NoticeRequest noticeRequest){
        return mybatisDaoContext.update(SQLID + "updatePreviewNum",noticeRequest);
    }
}
